package com.hymjweb.demo.hymj.native_bill_manage.sign_choose_detail.controller;

import com.hymjweb.demo.framework.result.BaseResultMap;
import com.hymjweb.demo.framework.sys.BaseController;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.native_bill_manage.sign_choose_detail.bean.BNativeBillSignChooseDetailPojo;
import com.hymjweb.demo.hymj.native_bill_manage.sign_choose_detail.service.BNativeBillSignChooseDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/pages/native_bill_manage/sign_choose_detail")
public class BNativeBillSignChooseDetailController extends BaseController {

    @Autowired
    private BNativeBillSignChooseDetailService bNativeBillSignChooseDetailService;


    @RequestMapping("/queryBillSignStatus")
    @ResponseBody
    public List<BNativeBillSignChooseDetailPojo> queryBillSignStatus(@RequestParam(required = true) String billId) throws Exception{
        if(DataTypeUtil.isEmptyStr(billId)){
            throwException("分单查询参数错误!");
        }
        return bNativeBillSignChooseDetailService.queryBillSignStatusByBillId(billId);
    }

    @RequestMapping("/addBillSignStatus")
    @ResponseBody
    public Object addBillSignStatus(@RequestBody(required = true) BNativeBillSignChooseDetailPojo pojo) throws Exception{
        if(pojo == null){
            throwException("添加分单签收状态参数错误!");
        }

        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("分单签收状态添加成功!");

        int affectRows = bNativeBillSignChooseDetailService.addBillSignStatus(pojo);

        if(affectRows<=SysConstant.INT_ZERO){
            baseResultMap.setOk(false);
            baseResultMap.setMessage("分单签收状态添加失败!");
        }
        return baseResultMap;
    }

    @RequestMapping("/deleteBillSignStatus")
    @ResponseBody
    public Object deleteBillSignStatus(@RequestParam(required = true) String id) throws Exception{
        if(DataTypeUtil.isEmptyStr(id)){
            throwException("删除分单签收状态参数错误!");
        }

        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("分单签收状态删除成功!");

        int affectRows = bNativeBillSignChooseDetailService.deleteBillSignStatusById(id);

        if(affectRows<=SysConstant.INT_ZERO){
            baseResultMap.setOk(false);
            baseResultMap.setMessage("分单签收状态删除失败!");
        }
        return baseResultMap;
    }

}
